#include "iostream"
#include "string"

// 定义状态枚举
enum State {
    idle,
    running,
    stopped
};

// 状态机类
class StateMachine {
private:
    State currentState;

public:
    // 初始化为idle
    StateMachine() : currentState(idle) {}

    // 当前状态
    State getCurrentState() const {
        return currentState;
    }

    // 处理事件并更新状态
    void handleEvent(const std::string& event) {
        if (currentState == idle && event == "start") {
            std::cout << "从 0 转换到 1" << std::endl;
            currentState = running;
        } else if (currentState == running && event == "stop") {
            std::cout << "从 1 转换到 2" << std::endl;
            currentState = stopped;
        } else if (currentState == stopped && event == "reset") {
            std::cout << "从 2 转换到 0" << std::endl;
            currentState = IDLE;
        } else {
            std::cout << "在状态 " << currentState << " 下没有为事件 " << event << " 定义转换" << std::endl;
        }
    }
};

int main() {
    StateMachine stateMachine;

    // 模拟事件处理
    stateMachine.handleEvent("start");
    stateMachine.handleEvent("continue"); 
    stateMachine.handleEvent("stop");
    stateMachine.handleEvent("reset");
    stateMachine.handleEvent("stop"); // idle

    // 输出最终状态
    std::string finalState;
    switch (stateMachine.getCurrentState()) {
        case idle:
            finalState = "0";
            break;
        case running:
            finalState = "1";
            break;
        case stopped:
            finalState = "2";
            break;
    }
    std::cout << "最终状态: " << finalState << std::endl;

    return 0;
}